/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SQLServer;

/**
 *
 * @author Betty
 */
import java.sql.*;

public class connectSQLServer{
    
    private Connection con = null;
    private final String defaultURL = "jdbc:sqlserver://localhost;databaseName=AnalysisTests;user=Java1;password=reddog16";

    private String databaseURL = null;
    
    public connectSQLServer()
    {
        databaseURL = defaultURL;
    }
    
    public connectSQLServer(String DatabaseURL)
    {
        this.databaseURL = DatabaseURL;  
    }
    
    public Connection Connect()
    {
        try
        {
            this.con = DriverManager.getConnection(databaseURL);
            return con;
        }
        catch(SQLException ex)
        {
            return null;
        }
    }
    
    public void closeConnection()
    {
        try
        {
            if (!this.con.isClosed())
            {
                this.con.close();
            }
        }catch (SQLException ex)
        {
        }
    }
    
    public ResultSet executeProc(String procCall)
    {
        ResultSet rs;
        Statement cs;
        
        try
        {
            if (con == null)
            {
                return null;
            }
            cs =  con.createStatement();
            rs = cs.executeQuery(procCall);
            //System.out.println(rs.getString(1));
        }catch(SQLException ex)
        {
            return null;
        }
        return rs;
    }
    
}

